import java.util.Scanner;
import java.util.TreeSet;

class Student implements Comparable<Student> {
    String name;
    String id;
    int age;

    public Student(String id, String name, int age) {

        this.name = name;

        this.id = id;

        this.age = age;
    }

    @Override
    public int compareTo(Student s) {

        int num = this.age - s.age;

        return num == 0 ? this.id.compareTo(s.id) : num;

    }
}


public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        TreeSet<Student> ts = new TreeSet<>();

        while (sc.hasNext()) {

            String str = sc.nextLine();

            String[] strs = str.split(" ");

            String name = strs[1];

            String id = strs[0];
            int age = Integer.parseInt(strs[2]);

            Student stu = new Student(id, name, age);

            ts.add(stu);
        }
        for (Student stu1 : ts) {

            System.out.println(stu1.id + ", " + stu1.name + ", " + stu1.age);
        }
    }
}
 
 